﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting .WinForms;
namespace Fang.Common.Print
{
    public partial class PrintViewer : Form
    {
        public PrintViewer()
        {
            InitializeComponent();
       
        }
        /// <summary>
        /// 报表数据源
        /// </summary>
        public DataTable  RDataSource
        {
            get;
            set;
        }
        /// <summary>
        /// 调用表名
        /// </summary>
        public string TableName
        {
            get;
            set;
        }
        /// <summary>
        /// 报表路径
        /// </summary>
        public string ReportFilePath
        {
            get;
            set;
        }
        private void PrintViewer_Load(object sender, EventArgs e)
        {
            try
            {
                ReportDataSource reportdatasource = new ReportDataSource(TableName, RDataSource);
                //this.ReportViewer.LocalReport.DataSources.Add(reportdatasource);
                this.ReportViewer.LocalReport.ReportPath = ReportFilePath;
                this.ReportViewer.RefreshReport();
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgBox(ex.Message + ex.Source);
            }
        }

        private void PrintViewer_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.ReportViewer.Dispose();
            this.Dispose();
        }
    }
}
